import { Module } from '@nestjs/common';
import { PrismaModule } from '@/prisma/prisma.module';
import { RedisModule } from '@/redis/redis.module';
import { MinioClientModule } from '@/minio/MinioClient.module';

import { ConfigModule, ConfigService } from '@nestjs/config';
import config from '@/utils/config';
import { JwtModule } from '@nestjs/jwt';
import { APP_GUARD } from '@nestjs/core';
import { LoginGuard } from '@/guard/login.guard';

import { AdminUserModule } from '@/crud/AdminUser/AdminUser.module';
import { UserControlModule } from '@/crud/UserControl/UserControl.module';
import { ScenicControlModule } from '@/crud/ScenicControl/ScenicControl.module';
import { CommunityControlModule } from '@/crud/CommunityControl/CommunityControl.module';
import { StatisticsModule } from '@/crud/Statistics/Statistics.module';

import { UserModule } from '@/crud/User/user.module';

import { AppController } from './app.controller';

@Module({
  imports: [
    PrismaModule,
    RedisModule,
    MinioClientModule,

    ConfigModule.forRoot({
      isGlobal: true,
      load: [config],
    }),
    JwtModule.registerAsync({
      global: true,
      useFactory(configService: ConfigService) {
        return {
          secret: configService.get('jwt.secret'),
          signOptions: {
            expiresIn: '30m',
          },
        };
      },
      inject: [ConfigService],
    }),

    AdminUserModule,
    UserControlModule,
    ScenicControlModule,
    CommunityControlModule,
    StatisticsModule,

    UserModule,
  ],
  providers: [
    {
      provide: APP_GUARD,
      useClass: LoginGuard,
    },
  ],
  controllers: [AppController],
})
export class AppModule {}
